// pages/paySuccess/index.js
var util = require('../../utils/util.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    isSuccess: false,
    orderId: '',
    checked: true
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log(options.orderId)
    this.setData({
      isSuccess: options.state
    })
    this.data.orderId = options.orderId;
  },
  onChange(event) {
    this.setData({
      checked: event.detail
    });
  },
  goHome(){
    if (this.data.checked && this.data.isSuccess == 1) {
      util.http({
        url: 'api/miniwechat/order/syngroup',
        method: 'POST',
        data: {
          user_id: util.isLogin().user_id,
          order_id: this.data.orderId,
        }
      }).then((data) => {
        wx.reLaunch({
          url: '/pages/index/index'
        })
      }).catch((err) => {
        wx.showToast({
          title: String(err),
          icon: 'none',
          duration: 2000
        })
      })
    } else {
      wx.reLaunch({
        url: '/pages/index/index'
      })
    }
    
    
  }
})